package com.brainardphotography.blog.web;

import java.util.Date;

import com.brainardphotography.blog.BlogEntry;
import com.brainardphotography.blog.dao.BlogEntryDAO;
import com.google.appengine.api.users.User;
import com.google.appengine.api.users.UserService;
import com.google.appengine.api.users.UserServiceFactory;
import com.google.inject.Inject;
import com.google.inject.servlet.SessionScoped;
import com.google.sitebricks.At;
import com.google.sitebricks.http.Get;

@At("/")
@SessionScoped
public class Home extends BasePage {
	private static final long serialVersionUID = -6090487643758064430L;
	
	private Date date = new Date();
	private User user = null;
	private BlogEntry blogEntry;

	@Inject
	private BlogEntryDAO entryDAO;
	
	public Date getDate() {
		return date;
	}

	public User getUser() {
		return this.user;
	}
	
	public BlogEntry getBlogEntry() {
		return this.blogEntry;
	}
	
	@Get
	public String get() {
		UserService users = UserServiceFactory.getUserService();
		
		user = users.getCurrentUser();

		this.blogEntry = entryDAO.getHomePageEntry();
		
		if(blogEntry == null)
			return "/about/";
		
		return null;
	}
}
